<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>瀑布流图片</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }

    .box {
      width: 260px;
      border: 1px solid black;
      background-color: #ffffff;
      padding: 2px;
      border-radius: 4px;
      display: inline-block;
    }

    .box>div {
      width: 100%;
    }

    .box>div>img {
      width: 100%;
      border-radius: 4px;
    }
  </style>
</head>

<body>
  <content>
    <div class="box">
      <div class="box-img">
        <img src="./img/0.png">
      </div>
    </div>
    <div class="box">
      <div class="box-img">
        <img src="./img/1.png">
      </div>
    </div>
    <div class="box">
      <div class="box-img">
        <img src="./img/2.png">
      </div>
    </div>
    <div class="box">
      <div class="box-img">
        <img src="./img/3.png">
      </div>
    </div>
    <div class="box">
      <div class="box-img">
        <img src="./img/4.png">
      </div>
    </div>
    <div class="box">
      <div class="box-img">
        <img src="./img/5.png">
      </div>
    </div>
  </content>
</body>
<script>
  "use strict";

  const content = document.querySelector("content");
  const boxs = content.querySelectorAll(".box")
  const box_imgs = content.querySelectorAll(".box-img")
  const imgs = content.querySelectorAll("img")

  // 获取图片的宽度
  const boxswidth = boxs[0].offsetWidth;
  // 获取浏览器的宽度
  const elementwidth = document.documentElement.clientWidth;
  // 计算出列数
  const num = ~~(elementwidth / boxswidth);
  // DOMContentLoaded
  document.addEventListener("load", () => {
    content.style.cssText = `width:${boxswidth*num}px;margin:0 auto`;
  });
</script>

</html>